﻿#pragma once
#include <algorithm>
#include <vector>
#include <random>

namespace as
{
	namespace tools
	{
		template<class T>
		static void random_shuffle(T beg, T end)
		{
			std::random_device rd;
			std::mt19937 g(rd());
			std::shuffle(beg, end, g);
		}

		template<class T>
		static void random_shuffle(std::vector<T> &v)
		{
			std::random_device rd;
			std::mt19937 g(rd());
			std::shuffle(v.begin(), v.end(), g);
		}

		/// <summary>
		/// 整数随机分布[beg,end)
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="beg">整数</param>
		/// <param name="end">整数</param>
		/// <returns>整数</returns>
		template<class T>
		static T random(T beg, T end)
		{
			std::random_device rd;
			std::mt19937 gen(rd());
			std::uniform_int_distribution<T> dis(beg, end);
			return dis(gen);
		}

		/// <summary>
		/// 实数随机分布[beg,end)
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="beg">实数</param>
		/// <param name="end">实数</param>
		/// <returns>实数</returns>
		template<class T>
		static T randomf(T beg, T end)
		{
			std::random_device rd;
			std::mt19937 gen(rd());
			std::uniform_real_distribution<T> dis(beg, end);
			return dis(gen);
		}
	}
}
